package br.com.processo.util.conversor;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;

public class ConverterGenerico {

	public void verificaEntradaAsObject(FacesContext context, UIComponent component, String value) {
		if (context == null) {
			throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro inesperado",
					"Problema no FacesContext do Conversor!"));
		}
		if (component == null) {
			throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro inesperado",
					"Problema no UIComponent do Conversor!"));
		}
		if (value.trim().equals("")) {
			throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro inesperado",
					"Entrada inválida!"));
		}
	}

	public void verificaEntradaAsString(FacesContext context, UIComponent component, Object value) {
		if (context == null) {
			throw new NullPointerException("context");
		}
		if (component == null) {
			throw new NullPointerException("component");
		}
		if ((value == null) || value.equals("")) {
			throw new IllegalArgumentException(value.toString());
		}
	}

}